using Fantasy;
using System;
using System.Diagnostics;
using UnityEngine;
using Debug = UnityEngine.Debug;
using QFramework;
using System.IO;
using System.Collections.Generic;

    public class FantsyNetModel : AbstractModel
    {
         
        public Scene scene { get; set; }
        public string RemoteAddress { get; set; }
        public string RemoteAddressPort { get; set; }
        public float DelayTime { get; set; }
        public NetworkProtocolType networkProtocolType { get; set; }
        public override bool Preload => true;
    protected override void OnInit()
    {
        Debug.Log("");
    }

       public  async FTask<IResponse> CallServer(IRequest request, long routeId = 0) 
        {
            var messag = await scene.Session.Call(request, routeId);
            return messag;
        }

        public async void StartInitFantsyAndConnect() 
        {

            scene = await Entry.Initialize(GetType().Assembly);
            Debug.Log($"Fantsy{RemoteAddress}:{RemoteAddressPort}");

            if (string.IsNullOrEmpty(RemoteAddress) || string.IsNullOrEmpty(RemoteAddressPort)|| networkProtocolType== NetworkProtocolType.None) 
            {
                Debug.LogError($"服务连接错误");
                return;
            }

            scene.Connect($"{RemoteAddress}:{RemoteAddressPort}", networkProtocolType, onConnectComplete, onConnectFail, onConnectDisconnect,6000);
        }

        private void onConnectFail()
        {
            Debug.Log("");
        }

        private void onConnectComplete()
        {

            Debug.Log("");
        }

        private void onConnectDisconnect()
        {
            Debug.Log("");
        }

    }
